using System;
using System.ComponentModel;

namespace IValidate
{
	public class ValidateMaxLengthAttribute : ModelValidatorBaseImpl
	{		
		public int MaxLength { get; private set; }

        public ValidateMaxLengthAttribute(int maxLength, string errorMessage, bool required)
			: base(errorMessage, required)
		{
			MaxLength = maxLength;
		}

		public override bool Validate(object value)
		{
			if (value == null) return false;
			return System.Convert.ToString(value).Length <= this.MaxLength;
		}
	}
}
